﻿using AutoMapper;
using MediatR;
using WMS.API.Application.Command.InventoryManagement;
using WMS.Domain.Entities.InventoryManagement;
using WMS.Domain.Entities.StocktakingManagement;
using WMS.ErrorCode;
using WMS.Interfactructure.Interfaces;

namespace WMS.API.Application.CommandHandlers.InventoryManagement
{
    /// <summary>
    /// 库存管理-箱子型号管理-新增箱子命令-grx
    /// </summary>
    public class AddboxCommandHandler : IRequestHandler<AddboxCommand, APIResult<int>>
    {
        private readonly IBaseRepository<BoxManagement> _boxbaseRepository;
        private readonly IMapper mapper;

        public AddboxCommandHandler(IBaseRepository<BoxManagement> boxbaseRepository, IMapper mapper)
        {
            _boxbaseRepository = boxbaseRepository;
            this.mapper = mapper;
        }
        /// <summary>
        ///新增箱子型号命令处理器
        /// </summary>
        /// <param name="request">请求</param>
        /// <returns></returns>
        public async Task<APIResult<int>> Handle(AddboxCommand request, CancellationToken cancellationToken)
        {
            APIResult<int> result = new APIResult<int>("新增箱子型号成功");
            result.Code = ResultCode.Success;

            BoxManagement box = mapper.Map<BoxManagement>(request);

            await _boxbaseRepository.AddAsync(box);

            return await Task.FromResult(result);
        }
    }
}
